package top.yaofengqiao.springcloudsimple.demo.biz.trigger.dubbo;

import org.apache.dubbo.config.annotation.DubboService;
import top.yaofengqiao.springcloudsimple.demo.api.IOrderDubboService;
import top.yaofengqiao.springcloudsimple.demo.api.dto.OrderDTO;
import top.yaofengqiao.springcloudsimple.demo.biz.domain.order.model.entity.OrderEntity;
import top.yaofengqiao.springcloudsimple.demo.biz.domain.order.service.IOrderService;

import javax.annotation.Resource;

/**
 * @author yfq
 * @date 2024/6/14 16:47
 * @description
 */
@DubboService
public class OrderDubboService implements IOrderDubboService {
    @Resource
    private IOrderService orderService;

    @Override
    public OrderDTO queryOrderByOrderNo(String orderNo) {
        OrderEntity orderEntity = orderService.queryByOrderNo(orderNo);
        return buildOrderDTO(orderEntity);
    }

    @Override
    public OrderDTO queryOrderByOrderId(long orderId) {
        OrderEntity orderEntity = orderService.queryByOrderId(orderId);

        return buildOrderDTO(orderEntity);
    }

    private OrderDTO buildOrderDTO(OrderEntity orderEntity) {
        if (orderEntity == null) return null;

        return OrderDTO.builder()
                .orderNo(orderEntity.getRechargeOrderNo())
                .title(orderEntity.getTitle())
                .orderAmount(orderEntity.getOrderAmount())
                .orderStatus(orderEntity.getOrderStatus())
                .build();
    }
}
